function ModuleDialogNote(doc, container, width, height, user, date, options) {
  this._doc = doc;
  this._container = container;
  this._width = width;
  this._height = height;
  this._user = user;
  this._date = date;
  this._options = options;
  
  this._object = (options && options.task) ? options.task : {};
  this._popupBox = (options && options.popupBox) ? options.popupBox : null;
  this._callbackFunc = (options && options.callback) ? options.callback : null;
  
  this._createElements();
};

ModuleDialogNote.prototype._createElements = function() {
  var unique = MiscUtils.unique(), _self = this;
  this._gui = new DialogNote(this._doc, this._container, this._width, this._height, this._user, this._date, this._options)._gui;
  
  this._loadData();
};

ModuleDialogNote.prototype._loadData = function() {
  DOMUtils.removeTableRows(this._gui.note, 1);
  var tr, td;
  tr = this._gui.note.insertRow(-1);
  td = tr.insertCell(-1);
  td.colSpan = 6;
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._notes = null;
  this._retrieveNotes();
};

ModuleDialogNote.prototype._verifyData = function() {
  if (this._notes) {
    this._updateElements();
  }
};

ModuleDialogNote.prototype._retrieveNotes = function() {
  var _self = this;
  var args = '&c=t.task_id=' + this._object.id;
  new RequestUtils()._mysql('pz_task_note', args, function(result, params) { _self._notes = result.data;
                                                                             _self._verifyData.call(_self);
                                                                           }, null);
};

ModuleDialogNote.prototype._updateElements = function() {
  var table, tr, td, radio, input, unique = MiscUtils.unique(), _self = this;
  DOMUtils.removeTableRows(this._gui.note, 1);

  if (this._notes.length == 0) {
    tr = this._gui.note.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 6;
    td.style.height = '24px';
    td.style.textAlign = 'left';
    td.style.paddingLeft = '5px';
    td.appendChild(document.createTextNode('n/a'));
  }
  
  for (var i = 0, il = this._notes.length; i < il; i++) {
    var item = this._notes[i];
    tr = this._gui.note.insertRow(-1);
    
    td = tr.insertCell(-1);
    if (item.note_is_canceled == 1) {
      td.style.textDecoration = 'line-through';
    }
    td.style.height = '24px';
    td.style.textAlign = 'left';
    td.style.padding = '0 5px';
    td.appendChild(document.createTextNode(SimpleDate.format(SimpleDate.fromStamp(item.note_date))));
    
    td = tr.insertCell(-1);
    if (item.note_is_canceled == 1) {
      td.style.textDecoration = 'line-through';
    }
    td.style.textAlign = 'left';
    td.style.padding = '0 5px';
    td.appendChild(document.createTextNode((item.user) ? item.user : '-'));
    
    td = tr.insertCell(-1);
    var itable = document.createElement('table');
    itable.style.width = '100%';
    itable.cellPadding = 0;
    itable.cellSpacing = 0;
    td.appendChild(itable);
    
    itr = itable.insertRow(-1);
    itd = itr.insertCell(-1);
    if (item.note_is_canceled == 1) {
      itd.style.textDecoration = 'line-through';
    }
    itd.style.textAlign = 'left';
    itd.style.padding = '0 0 0 5px';
    itd.style.border = 0;
    itd.style.height = '23px';
    itd.style.lineHeight = '23px';
    var div = document.createElement('div');
    div.style.textOverflow = 'ellipsis';
    div.style.overflow = 'hidden';
    div.style.width = '478px';
    div.style.whiteSpace = 'nowrap';
    if (item.note_content.length != 0) {
      div.appendChild(document.createTextNode(item.note_content));
    } else {
      div.appendChild(document.createTextNode('(none)'));
    }
    itd.appendChild(div);
    
    itd = itr.insertCell(-1);
    itd.style.border = 0;
    var more = document.createElement('img');
    more.src = 'image/enlarge.png';
    more.style.cursor = 'pointer';
    more.onclick = function() { var pos, func1, func2;
                                var pos = DOMUtils.findPos(this);
                                _self._popupBox = new ModulePopupBoxSimple();
                                var div = document.createElement('div');
                                func1 = function() { _self._popupBox._close();
                                                   };
                                div.appendChild(MiscUtils.span(item.note_content));
                                MiscUtils.dialog(_self._popupBox, pos, div, func1, null);
                                return false;
                                };
    if (item.note_content.length != 0 && item.note_content.length > 48) {
    itd.appendChild(more);
    }
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    var remove = document.createElement('img');
    remove.src = 'image/delete.png';
    remove.style.cursor = 'pointer';
    remove._item = item;
    remove.onclick = function() { this._item.note_is_canceled = 1;
                                  var pos = DOMUtils.findPos(this);
                                  new RequestUtils()._write('pz_task_note', [this._item], [], function() { _self._retrieveNotes(); }, { pos: pos });
                                };
    if (item.note_is_canceled != 1 && this._object.is_canceled != 1) {
      td.appendChild(remove);
    }
  }
  
  this._note = pz_task_note.instance();
 
  if(this._object.is_canceled == 1){
    this._gui.addNote.disabled = true;
    this._gui.add.disabled = true;
  }
  this._gui.addNote.value = this._note.note_content;
  this._gui.addNote.onchange = function() { _self._note.note_content = this.value; };
  
  this._gui.add.onclick = function() { _self._note.note_user_id = _self._user.id;
                                       _self._note.note_date = _self._date;
                                       _self._note.task_id = _self._object.id;
                                       var pos = DOMUtils.findPos(this);
                                       new RequestUtils()._write('pz_task_note', [_self._note], [], function() { _self._retrieveNotes(); }, { pos: pos });
                                     };
  this._gui.close.onclick = function() { _self._popupBox._close(); _self._callbackFunc(); };
};